/**
 * 
 */
package ae.pcfc.cldos.online.web.controller.client.company.visa.view;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import ae.pcfc.cldos.online.common.ConstantsCommon.Steps;
import ae.pcfc.cldos.online.common.delegate.EmploymentVisaDelegate;
import ae.pcfc.cldos.online.common.vo.CommentsVO;
import ae.pcfc.cldos.online.common.vo.EmployeVisaVO;
import ae.pcfc.cldos.online.common.vo.FileVO;
import ae.pcfc.cldos.online.common.vo.employee.details.AddressDetailsVO;
import ae.pcfc.cldos.online.common.vo.employee.details.EmployeeDetailsVO;
import ae.pcfc.cldos.online.common.vo.employee.details.PassportDetailsVO;
import ae.pcfc.cldos.online.common.vo.employee.details.PersonalDetailsVO;
import ae.pcfc.cldos.online.web.Constants;
import ae.pcfc.cldos.online.web.ViewPath;
import ae.pcfc.cldos.online.web.ViewUtils;
import ae.pcfc.cldos.online.web.controller.base.BaseNewVisaController;
import ae.pcfc.cldos.online.web.model.EmploymentVisaLicenseInfo;

/**
 * @author Abed
 *
 */
@Controller
@RequestMapping(value = ViewPath.__ADMIN_EMPLOYMENT_VISA_VIEW)
public class AdminEmploymentVisaViewController extends BaseNewVisaController{
	
	@Autowired
	@Qualifier("employmentVisaDelegate")
	private EmploymentVisaDelegate employmentVisaDelegate;
	
	
	@ModelAttribute
	public void populateBreadCrumbs(ModelMap model, @RequestParam String appId) {
		breadCrumbsFactoryService.populateallAppReqDtlBreadCrumb(model);
	}
	
	@ModelAttribute(Constants.__COMPANY_EMPLOYMENT_VISA_REVIEWER_LICENSE_INFO_REQUEST_MODEL_KEY)
	public EmploymentVisaLicenseInfo populateRegisterEmploymentVisaReviewerInfoModel(@RequestParam String appId,
			HttpServletRequest request, ModelMap model) throws Exception {
		EmploymentVisaLicenseInfo employmentVisaInfo = new EmploymentVisaLicenseInfo();
		
		EmployeVisaVO employeVisaVO = employmentVisaDelegate.getEmployeeVisaViewDtls(encryptionDelegate.decodeAndDecrypt(appId), getUserVO(), Steps.ALL_APP_REQUEST);
		
		//get all the employment visa related info like address details, personal details, passport details and employee details
		AddressDetailsVO addressDetailsVO = employeVisaVO.getAddressDetailsVO();
		mapper.map(addressDetailsVO, employmentVisaInfo);
		CommentsVO commentsVO = employeVisaVO.getCommentsVO();
		mapper.map(commentsVO, employmentVisaInfo);
		EmployeeDetailsVO employeeDetailsVO = employeVisaVO.getEmployeeDetailsVO();
		mapper.map(employeeDetailsVO, employmentVisaInfo);
		PassportDetailsVO passportDetailsVO = employeVisaVO.getPassportDetailsVO();
		mapper.map(passportDetailsVO, employmentVisaInfo);
		PersonalDetailsVO personalDetailsVO = employeVisaVO.getPersonalDetailsVO();
		mapper.map(personalDetailsVO, employmentVisaInfo);
		employmentVisaInfo.setWfStatus(employeVisaVO.getWfStatus());
		employmentVisaInfo.setGsEmpStatus(employeVisaVO.getGsEmpStatus());
		
		List<FileVO> fileVOList = employeVisaVO.getFileVOList();
		// putting files and comments to the view
		model.put("files", fileVOList);
		model.put("comments", employeVisaVO.getApplicationCommentVOs());
		
		return employmentVisaInfo;
	}
	
	
	@RequestMapping(value = "/form.htm", method = RequestMethod.GET)
	public ModelAndView form() {
		return ViewUtils.DEFAULT_VIEW;
	}
	
	@RequestMapping(value = "/form.htm", method = RequestMethod.POST)
	public ModelAndView backtoMain() {
		return ViewUtils.DEFAULT_VIEW;
	}
	
	
}
